package com.firegod.live.controller;

import com.alibaba.fastjson.JSONObject;
import com.firegod.commonutils.vo.ResultVo;
import com.firegod.live.service.LiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "直播管理")
@RestController
@RequestMapping("/live")
@CrossOrigin
public class LiveController {

    @Autowired
    private LiveService liveService;

    @GetMapping("/join")
    @ApiOperation("加入直播（前端向后端发送）")
    public ResultVo join(String courseId) {
        return ResultVo.ok().data(liveService.join(courseId));
    }

    @PostMapping("/createLive")
    @ApiOperation("创建房间")
    public ResultVo createLive(@RequestBody JSONObject jsonObject) {
        String courseId = jsonObject.getString("liveId");
        liveService.createLive(courseId);
        return ResultVo.ok();
    }

    @GetMapping("/heartBeat")
    @ApiOperation("创建房间")
    public ResultVo inLive(String courseId) {
        liveService.inLive(courseId);
        return ResultVo.ok();
    }

//    @PostMapping("/leave")
//    @ApiOperation("退出直播（直播端向后端发送）")
//    public ResultVo leave(@RequestBody JSONObject jsonObject) {
//        String userId = jsonObject.getString("userId");
//        String roomId = jsonObject.getString("roomId");
//        liveService.leave(userId, roomId);
//        return ResultVo.ok();
//    }
}
